package org.simple.wechat.demo.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.simple.wechat.demo.ienum.IEnum;

import java.io.IOException;

/***
 * @author gaoqijin
 * @date 2020-9-10
 * @Description
 */
public class IEnumSerializer2 extends JsonSerializer<IEnum> {

  @Override public void serialize(IEnum iEnum, JsonGenerator jsonGenerator,
      SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName("code");
    jsonGenerator.writeString(String.valueOf(iEnum.getCode()));
    jsonGenerator.writeFieldName("name");
    jsonGenerator.writeString(iEnum.getDesc());
    jsonGenerator.writeEndObject();
  }
}
